package com.cn.wanxi.servlet.front;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.service.ICompanyService;
import com.cn.wanxi.service.INavService;
import com.cn.wanxi.service.IProductService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;
import com.cn.wanxi.service.impl.NavServiceImpl;
import com.cn.wanxi.service.impl.ProductServiceImpl;
import com.cn.wanxi.util.DataEncoding;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/common/data")
public class CommonDataServlet extends HttpServlet {
    ICompanyService companyService = new CompanyServiceImpl();
    INavService navService = new NavServiceImpl();
    IProductService productService = new ProductServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        DataEncoding.setCharacterEncoding(req,resp);
        DataEncoding.setJsonContentType(resp);
        CompanyModel companyModel = companyService.getCompany();
        List<NavModel> navList = navService.getNavList();
//        List<ProductModel> pictures = productService.getProductList(page, pdt_type);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("company", companyModel);
        jsonObject.put("navs",navList);
//        jsonObject.put("pictures",pictures);
        resp.getWriter().print(jsonObject);
    }
}
